import java.util.Arrays;

public class Test {
    public static void main(String[] args) throws CloneNotSupportedException {
        Point point = new Point();
        point.setX(1);
        System.out.println(point.getX());


        A a = new A();
        System.out.println(a);
        A b = (A) a.clone();
        b.c.c = 100;
        System.out.println(a);


        int[] arr = {2, 1, 30, 4, 5, 6, 7, 3, 31};
        quickSort(arr,0,arr.length-1);
        System.out.println(Arrays.toString(arr));

        int i = binarySearch(arr, 7);
        System.out.println(i);
    }

    public static void quickSort(int[] arr, int start, int end) {
        if (start < end) {
            //标准数
            int stard = arr[start];
            //定义左边的指针
            int low = start;
            //定义右边的指针
            int high = end;
            while (low < high) {
                //首先判断右边的数字是否大于标准数
                //如果是的话只需要把右边的指针向前移动一位
                while (low < high && stard < arr[high]) {
                    high--;
                }
                //如果不是就需要跳出循环，把右边的数字赋给左边的数字
                arr[low] = arr[high];

                //再判断左边的数字是否小于标准数
                //如果是的话只需要把左边的指针向前移动一位
                while (low < high && stard > arr[low]) {
                    low++;
                }
                //如果不是就会跳出循环，把左边的数字赋值给右边的数字
                arr[high] = arr[low];
            }
            //再把标准数赋值给现在low和high重合位置的值
            arr[low] = stard;

            // 使用递归的思想
            quickSort(arr, 0, low);
            quickSort(arr, low + 1, end);
        }
    }

    public static void insertSort(int[] arr) {
        int len = arr.length;
        int preIndex = 0, current = 0;
        for (int i = 1; i < len; i++) {
            preIndex = i - 1;
            current = arr[i];
            while (preIndex >= 0 && arr[preIndex] > current) {
                arr[preIndex + 1] = arr[preIndex];
                preIndex--;
            }
            arr[preIndex + 1] = current;
        }
    }


    public static void bubbleSort(int[] arr) {
        int len = arr.length;
        int temp = 0;
        for (int i = 0; i < len - 1; i++) {
            for (int j = i; j < len - 1 - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
    }

    public static int binarySearch(int[] sort, int target) {
        if (target < sort[0] || target > sort[sort.length - 1]) return -1;
        int low = 0;
        int high = sort.length - 1;
        int mid = 0;
        while (low <= high) {
            mid = (low + high) / 2;
            if (target > sort[mid]) low = mid + 1;
            else if (target < sort[mid]) high = mid - 1;
            else return mid;
        }
        return -1;
    }
}

class Point<T> {
    private T x;
    private T y;

    public T getX() {
        return x;
    }

    public void setX(T x) {
        this.x = x;
    }

    public T getY() {
        return y;
    }

    public void setY(T y) {
        this.y = y;
    }
}


class A implements Cloneable {
    int a = 10;
    int b = 20;
    B c = new B();

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    @Override
    public String toString() {
        return "A{" +
                "a=" + a +
                ", b=" + b +
                ", c=" + c +
                '}';
    }
}

class B {
    int c = 10;

    @Override
    public String toString() {
        return "B{" +
                "c=" + c +
                '}';
    }
}
